package game.rwalk.control;

import game.rwalk.entity.Player;
import game.rwalk.utility.Constants;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;

public class SelectPlayerScreen {
	
	public int indexPlayer;
	private ArrayList<Player> players;
	private Context context;
	
	private Paint bmpPaint = new Paint(), paint1 = new Paint(), paint2 = new Paint();
	
	public SelectPlayerScreen(ArrayList<Player> players, Context context) {
		this.players = players;
		this.context = context;
		
		paint1.setTextSize(20);
		paint2.setTextSize(20);
		paint1.setARGB(255, 48, 186, 219);
		paint2.setARGB(255, 226, 54, 54);
		paint1.setStyle(Style.FILL_AND_STROKE);
		paint2.setStyle(Style.FILL_AND_STROKE);
		
		bmpPaint.setARGB(50, 255, 255, 255);
		
		for(int i = 0; i < 4; i++) {
			players.get(i).left = Constants.SP_MARGIN_LEFT;
			players.get(i).top = Constants.SP_TEXT_MARGIN_TOP + i*(Constants.SP_PADDING + (int)paint1.getTextSize());
		}
	}
	
	public void onDraw(Canvas canvas) {
		
		//draw label
		
		//draw text
		for(int i = 0; i < 4; i++) {
			if(!players.get(i).isPlayed) { //draw by paint1
				canvas.drawText(	players.get(i).name,
									players.get(i).left,
									players.get(i).top,
									paint1
								);
			} else {	//draw by paint2
				canvas.drawText(	players.get(i).name,
									players.get(i).left,
									players.get(i).top,
									paint2
								);
			}
			
			canvas.drawRect(0, players.get(i).top, 320, players.get(i).top + paint1.getTextSize(), bmpPaint);
		}
	}
	
	public boolean selectPlayer(int x, int y) {
		
		for(int i = 0; i < 4; i++) {
			int bottom = players.get(i).top + (int)paint1.getTextSize();
			
			if((y > players.get(i).top) && (y < bottom)) {
				indexPlayer = i;
				players.get(i).isPlayed = true;
				return true;
			}
		}
		return false;
	}
}
